package com.dgshanger.sanhxiaofeisc.ui.home.activity

import android.support.v7.widget.LinearLayoutManager
import com.dgshanger.sanhxiaofeisc.R
import com.dgshanger.sanhxiaofeisc.adapter.ShopPhotoListAdapter
import com.dgshanger.sanhxiaofeisc.mvp.contract.ShopPhotoListContract
import com.dgshanger.sanhxiaofeisc.mvp.presenter.ShopPhotoListPresenter
import com.dgshanger.sanhxiaofeisc.ui.home.utils.ActivityCloseUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.xx.baseuilibrary.mvp.BaseMvpActivity
import kotlinx.android.synthetic.main.activity_shop_photo_list.*

/**
 * Created by JacobHHH on 2018/4/19.
 */
class ShopPhotoListActivity : BaseMvpActivity<ShopPhotoListContract.Model,ShopPhotoListContract.View,ShopPhotoListPresenter>(),ShopPhotoListContract.View{

    private lateinit var mShopPhotoListAdapter : ShopPhotoListAdapter

    override fun createPresenter(): ShopPhotoListPresenter = ShopPhotoListPresenter()

    override fun getActivityLayoutId(): Int = R.layout.activity_shop_photo_list

    override fun initData() {
        initView()

    }

    private fun initView() {
        val JsonStr = intent.getStringExtra("shopListImages")
        tv_title.text=intent.getStringExtra("title")
        val retList = Gson().fromJson<List<String>>(JsonStr,
                object : TypeToken<List<String>>() {

        }.type)
        rec_photo.layoutManager=LinearLayoutManager(mContext)
        mShopPhotoListAdapter=ShopPhotoListAdapter(R.layout.item_shop_photo_list,retList)
        rec_photo.adapter=mShopPhotoListAdapter
    }

    override fun initEvent() {
        ActivityCloseUtils.getInstance()!!.finishActivity(this,rec_photo)
    }

    override fun onDestroy() {
        super.onDestroy()
        ActivityCloseUtils.getInstance()!!.detach()
    }

}